package com.tanhua.model.vo;

import com.tanhua.model.domain.UserInfo;
import com.tanhua.model.mongo.Visitors;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;

/**
 * @author Xiao
 * @version 1.0
 * @description
 * @date 2021/11/1
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class VisitorsVO implements Serializable {
    private Long id; //用户id
    private String avatar;
    private String nickname;
    private String gender; //性别 man woman
    private Integer age;
    private String[] tags;
    private Long fateValue; //缘分值

    /**
     * 在vo对象中，补充一个工具方法，封装转化过程
     */
    public static VisitorsVO init(UserInfo userInfo, Visitors visitors) {
        VisitorsVO visitorsVO = new VisitorsVO();
        BeanUtils.copyProperties(userInfo, visitorsVO);
        if(userInfo.getTags() != null) {
            visitorsVO.setTags(userInfo.getTags().split(","));
        }
        visitorsVO.setFateValue(visitors.getScore().longValue());
        return visitorsVO;
    }
}
